package ca.tatham.senssim.util;

public class Counter
{
  private final int m_mod;
  private int m_count = 0;
  private int m_total = 0;

  public Counter(int mod)
  {
    m_mod = mod;
  }

  public Counter()
  {
    this(0);
  }

  public void increment(int amount)
  {
    m_count += amount;
    m_total += amount;
    if (m_mod != 0)
    {
      m_count %= m_mod;
    }
  }

  public void increment()
  {
    increment(1);
  }

  public int get()
  {
    return m_count;
  }

  public int getTotal()
  {
    return m_total;
  }

  public void reset()
  {
    m_count = 0;
  }

  @Override
  public String toString()
  {
    return Integer.toString(get());
  }

}
